<template>
	<div>

		<!-- 初筛弹框 -->
		<el-dialog 
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="筛选点位" center :visible.sync="dialogFirstFilter" width="95%"
			@close="dialogCUClose('firstFilterForm')" class="first-dialog">
			<!-- 初筛弹框头 -->
			<div class="flex flex-direction justify-center align-center" style="position: relative;">
				<div class="flex justify-center align-center text-xl text-bold">
					<div class="margin-right">期望时间</div>
					<div class="text-red">{{firstFilterForm.date_range[0].substring(0,10)}}</div>
					<div class="margin-lr-sm">~</div>
					<div class="text-red">{{firstFilterForm.date_range[1].substring(0,10)}}</div>
				</div>
			</div>
			<!-- 初筛条件 -->
			<el-divider content-position="left"><span class="text-lg text-bold">筛选点位</span></el-divider>
			<div class="search">
				<el-form ref="firstFilterForm" :inline="true" :model="firstFilterForm" class="form-inline" size="mini"
					:rules="firstFilterFormRules" v-loading="dialogFirstLoading">
					<div class="search-form-card-group">
						<div class="search-form-card">
							<div class="card-title">位置</div>
							<el-form-item label="省市">
								<el-cascader filterable v-model="firstFilterForm.pca" filterable placeholder="请选择省市"
									:options="pcAll" @change="changeCity"></el-cascader>
							</el-form-item>
							<el-form-item label="行政区划" prop="adcodes">
								<el-select clearable filterable multiple v-model="firstFilterForm.adcodes"
									placeholder="请选择行政区划">
									<el-option v-for="item in areaAll" :key="item.value" :label="item.label"
										:value="item.value" />
								</el-select>
							</el-form-item>
							<el-form-item label="地址">
								<el-input clearable v-model="firstFilterForm.address" placeholder="请输入搜索地址"
									class="long-input">
									<el-button slot="append" icon="el-icon-search" @click.native="searchAddress">
									</el-button>
								</el-input>
								<div class="flex justify-start align-center flex-wrap" style="width: 382px;">
									<el-tag class="margin-lr-xs margin-top-xs"
										v-for="(address, addressIndex) in firstFilterForm.address_circle_locations"
										:key="address.id" closable size="mini" type="parimary"
										@close="closeAddressTag(addressIndex)">
										{{address.title}}
									</el-tag>
								</div>
							</el-form-item>
							<el-form-item label="辐射半径" prop="address_circle.radius">
								<el-input v-model="firstFilterForm.address_circle.radius" type="number" :min="1">
									<template slot="append">米</template>
								</el-input>
							</el-form-item>
						</div>
						<div class="search-form-card">
							<div class="card-title">楼盘</div>
							
							<el-row>
								<el-form-item label="楼盘" prop="building_area_ids">
									<el-select clearable filterable multiple v-model="firstFilterForm.building_area_ids"
										placeholder="请选择楼盘" class="select-multiple2">
										<el-option v-for="item in buildingAreaList" :key="item.id" :label="item.name"
											:value="item.id">
											<span style="float: left">{{ item.name }}</span>
										</el-option>
									</el-select>
									<div class="text-gray text-sm"
										v-show="(firstFilterForm.building_area_ids || []).length > 0">已选中<span
											class="text-blue">{{(firstFilterForm.building_area_ids || []).length}}</span>个楼盘
									</div>
								</el-form-item>
								<el-form-item label="地图框选">
									<div style="width:140px">
										<el-button class="text-underline" icon="el-icon-map-location" type="text" size="mini" 
										@click="openMapChoose">地图</el-button>
									</div>
								</el-form-item>
								<el-form-item>
									<el-tooltip slot="label" placement="top" content="使用模板导入,快速选中楼盘">
										<span>导入楼盘<i class="el-icon-question"></i></span>
									</el-tooltip>
									<div style="width:140px">
										<el-button class="text-underline" type="text" size="mini"
											@click="downloadBuildings">下载模板</el-button>
										<el-button class="text-underline margin-left-sm" type="text" size="mini"
											@click="uploadBuildings">批量导入</el-button>
									</div>
								</el-form-item>
								<el-form-item label="楼盘辐射" prop="is_building_circle">
									<el-switch v-model="firstFilterForm.is_building_circle" size="mini" active-text="是"
										inactive-text="否">
									</el-switch>
								</el-form-item>
								<el-form-item label="辐射半径" prop="building_circle.radius"
									v-show="!!firstFilterForm.is_building_circle">
									<el-input v-model="firstFilterForm.building_circle.radius" type="number" :min="1">
										<template slot="append">米</template>
									</el-input>
								</el-form-item>
							</el-row>
							<el-row class="margin-top-xs">
								<el-form-item label="楼盘类型" prop="type_ids">
									<el-select clearable filterable multiple v-model="firstFilterForm.type_ids"
										placeholder="请选择楼盘类型" style="width:100%">
										<el-option v-for="item in buildingTypes" :key="item.id" :label="item.name"
											:value="item.id">
										</el-option>
									</el-select>
								</el-form-item>
								<el-form-item label="均价下限" prop="price_range.min">
									<el-col :span="24">
										<el-input v-model="firstFilterForm.price_range.min" type="number" :min="1">
											<template slot="append">元</template>
										</el-input>
									</el-col>
								</el-form-item>
								<el-form-item label="均价上限" prop="price_range.max">
									<el-col :span="24">
										<el-input v-model="firstFilterForm.price_range.max" type="number" :min="1">
											<template slot="append">元</template>
										</el-input>
									</el-col>
								</el-form-item>
							</el-row>
						</div>
						<div class="search-form-card">
							<div class="card-title">其他</div>
							<el-form-item prop="industry_id">
								<el-tooltip slot="label" placement="top" content="选择客户需要投放的行业">
									<span>投放行业<i class="el-icon-question"></i></span>
								</el-tooltip>
								<el-select clearable filterable v-model="firstFilterForm.industry_id"
									placeholder="选择投放行业" class="select-multiple2">
									<el-option v-for="item in industryList" :key="item.id" :label="item.name"
										:value="item.id" :disabled="!item.status || !!item.deleted_at">
										<span style="float: left">{{ item.name }}</span>
										<span
											:style="{float:'right',color:(!!item.deleted_at?'#e54d42':(!item.status?'#8492a6':'')),fontSize:'12px'}">
											{{!!item.deleted_at?'已删除':(!item.status?'已禁用':'')}}</span>
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="商圈">
								<el-select clearable filterable multiple v-model="firstFilterForm.trade_area_selected"
									placeholder="请选择商圈" size="mini" value-key="id" class="select-multiple2">
									<el-option v-for="item in tradeAreaAll" :key="item.id" :label="item.title"
										:value="item" style="width: 100%;">
										<div class="flex justify-between align-center flex-no-wrap">
											<div class="text-df">{{item.title}}</div>
											<div class="text-xs text-gray margin-left">{{item.address}}</div>
										</div>
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="辐射半径" prop="business_circle.radius">
								<el-input v-model="firstFilterForm.business_circle.radius" type="number" :min="1">
									<template slot="append">米</template>
								</el-input>
							</el-form-item>
						</div>
						<div class="search-form-card" v-show="(point_types || []).length > 1">
							<div class="card-title">点位</div>
							<!-- <el-form-item label="套餐" prop="is_combo" v-show="(point_types || []).length > 1">
								<el-switch v-model="firstFilterForm.is_combo" size="mini" active-text="是"
									inactive-text="否" @change="(val) => changeIsCombo(val, false)">
								</el-switch>
							</el-form-item> -->
							<el-form-item label="点位类型" prop="point_type_ids"
								v-show="(point_types || []).length > 1 && !firstFilterForm.is_combo">
								<el-select clearable filterable multiple v-model="firstFilterForm.point_type_ids"
									placeholder="选择点位类型" @change="changePointType" class="select-multiple2">
									<el-option v-for="item in point_types" :key="item.id" :label="item.name"
										:value="item.id">
										<span style="float: left">{{ item.name }}</span>
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="套餐" prop="combo_ids"
								v-show="(active_combo_list || []).length > 1 && !!firstFilterForm.is_combo">
								<el-select clearable filterable multiple v-model="firstFilterForm.combo_ids"
									placeholder="请选择套餐" class="select-multiple2">
									<el-option v-for="item in active_combo_list" :key="item.id" :label="item.name"
										:value="item.id">
										<span style="float: left">{{ item.name }}</span>
									</el-option>
								</el-select>
							</el-form-item>
						</div>
						<div style="margin:0 10px 0; width: 100%;" class="flex justify-center align-center">
							<el-button size="mini" type="primary" plain @click="searchSubmit('firstFilterForm')">筛选</el-button>
							<el-button size="mini" type="info" plain @click="searchReset('firstFilterForm')">重置</el-button>
						</div>
					</div>
				</el-form>
			</div>
			
			<!-- 初筛结果 -->
			<el-divider content-position="left"><span class="text-lg text-bold">筛选结果</span></el-divider>
			<div class="flex justify-end align-center flex-no-wrap margin-tb-sm">
				<el-button size="mini" type="primary" plain round @click.native="exportFirstExcel()" :disabled="(firstResultsSum.all || 0) == 0">导出空位</el-button>
			</div>
			<el-table id="firstTable" ref="firstResultsTable" :data="firstResults" tooltip-effect="dark" v-loading="firstResultsLoading"
				style="width: 100%" border row-key="id" max-height="700px" size="mini" show-summary
				:summary-method="getFirstSummaries" :row-class-name="getFirstRowClassName"
				:cell-class-name="getFirstCellClassName">
				<el-table-column type="index" label="序号" width="50" fixed="left">
					<template slot-scope="scope">
						<span>{{ scope.$index + 1 }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="name" min-width="120" fixed="left">
					<template slot="header" slot-scope="scope">
						<el-tooltip class="item" effect="dark" content="未安装设备的楼盘,不能进行点位分配" placement="top">
							<span>楼盘 <i class="el-icon-question"></i></span>
						</el-tooltip>
					</template>
					<template slot-scope="scope">
						<span class="">{{scope.row.name}}<span v-if="!scope.row.has_device" class="text-red">
								(未安装设备)</span></span>
					</template>
				</el-table-column>
				<el-table-column prop="area" min-width="100" label="区" fixed="left" sortable></el-table-column>

				<el-table-column align="center" v-for="pointTypeId in (firstFilterForm.result_point_type_ids||[])"
					:key="pointTypeId">
					<span slot="header">{{point_types_map.get(pointTypeId).name}}</span>
					<el-table-column :prop="pointTypeId+'_preset'" label="预设" min-width="50" align="center">
						<template slot-scope="scope">
							<span class="">{{scope.row.preset_point_counts[''+pointTypeId] || 0}}</span>
						</template>
					</el-table-column>
					<el-table-column :prop="pointTypeId+'_all'" label="已装" min-width="50" align="center">
						<template slot-scope="scope">
							<span
								class="text-blue">{{(((scope.row.points || [])[''+pointTypeId] || {}).all_count || 0)}}</span>
						</template>
					</el-table-column>
					<el-table-column :prop="pointTypeId+'_used'" label="上刊" min-width="50" align="center">
						<template slot-scope="scope">
							<span
								class="text-red">{{(((scope.row.points || [])[''+pointTypeId] || {}).used_devices || []).length}}</span>
						</template>
					</el-table-column>
					<el-table-column :prop="pointTypeId+'_lock'" label="锁定" min-width="50" align="center">
						<template slot-scope="scope">
							<span
								class="text-orange">{{(((scope.row.points || [])[''+pointTypeId] || {}).lock_devices || []).length}}</span>
						</template>
					</el-table-column>
					<el-table-column :prop="pointTypeId+'_can'" label="空闲" min-width="50" align="center">
						<template slot-scope="scope">
							<span
								class="text-green text-bold">{{(((scope.row.points || [])[''+pointTypeId] || {}).can_devices || []).length}}</span>
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="操作" width="80px" align="center" fixed="right">
					<template slot-scope="scope">
						<el-button icon="el-icon-delete" size="mini" plain type="danger"
							@click="delFirstBuilding(scope.$index)"  circle></el-button>
					</template>
				</el-table-column>
			</el-table>
			<!-- 初筛按钮 -->
			<span slot="footer" class="flex justify-center align-center">
				<el-button class="margin-lr-sm" @click.native="dialogFirstFilter=false" size="mini">取 消</el-button>
				<el-tooltip placement="top" :disabled="(firstResultsSum.all || 0) > 0" content="空闲点位须大于0">
					<div class="margin-lr-sm">
						<el-button type="primary" @click.native="toSecondFilter()" size="mini"
							:disabled="(firstResultsSum.all || 0) == 0">{{!!isOnlyExport?'规则过滤':'点位分配'}}</el-button>
					</div>
				</el-tooltip>
			</span>
		</el-dialog>
		
			
		<!-- 分配点位弹框 -->
		<el-dialog :close-on-click-modal="false" title="点位分配" center :visible.sync="dialogSecondFilter" width="95%"
			@close="dialogCUClose('secondFilterForm')">
			<!-- 分配弹框头 -->
			<div class="flex flex-direction justify-center align-center" style="position: relative;">
				<div class="flex justify-center align-center text-xl text-bold">
					<div class="margin-right">期望时间</div>
					<div class="text-red">{{secondFilterForm.date_range[0].substring(0,10)}}</div>
					<div class="margin-lr-sm">~</div>
					<div class="text-red">{{secondFilterForm.date_range[1].substring(0,10)}}</div>
				</div>
			</div>
			<!-- 规则过滤 -->
			<el-divider content-position="left" v-if="(Object.keys(pointRuleObj || {}) || []).length > 0"
				key="ruleTitle">
				<span class="text-lg text-bold">规则过滤</span>
			</el-divider>
			<div class="flex justify-start align-center flex-wrap text-sm" style="width: 100%"
				v-if="(Object.keys(pointRuleObj || {}) || []).length > 0" key="rules" v-loading="loadingRules">
				<el-card shadow="never" class="margin-xs" v-for="pRuleId in (Object.keys(pointRuleObj) || [])"
					:key="pRuleId" v-if="(pointRuleObj[''+pRuleId].rules || []).length>0">
					<span slot="header" class="text-bold">{{(point_types_map.get(parseInt(pRuleId)) || {}).name}}</span>
					<div class="flex justify-start align-center flex-wrap">
						<el-card shadow="never" style="line-height: 28px;" class="margin-lr-xs"
							v-for="rule in pointRuleObj[''+pRuleId].rules" :key="pRuleId+'_'+rule.id">
							<div v-if="rule.id==1||rule.id==2" :key="'rule'+pRuleId+'_'+rule.id">
								<el-switch v-model="rule.on" size="mini" class="margin-right-xs"
									@change="(val) => changRuleSwitch(pRuleId, rule.id, val)" />{{rule.name}}
								<el-input-number v-model="rule.n" :controls="false" size="mini" :min="1" step-strictly
									class="margin-left-xs" @change="(val) => changRuleN(pRuleId, val)" /> 个
							</div>
							<div v-else-if="rule.id==3" :key="'rule'+pRuleId+'_'+rule.id">
								<el-switch v-model="rule.on" size="mini" class="margin-right-xs"
									@change="(val) => changRuleSwitch(pRuleId, rule.id, val)" /> {{rule.name}}1个
							</div>
							<div v-else-if="rule.id==4||rule.id==5||rule.id==6" :key="'rule'+pRuleId+'_'+rule.id">
								<el-switch v-model="rule.on" size="mini" class="margin-right-xs"
									@change="(val) => changRuleSwitch(pRuleId, rule.id, val)" />{{rule.name}}
							</div>
							<div v-else-if="rule.id==7" :key="'rule'+pRuleId+'_'+rule.id">
								<el-select clearable filterable multiple v-model="rule.appoint" size="mini"
									placeholder="限定楼层" style="width:100%"
									@change="(val) => changeRuleAppoint(pRuleId, rule.id, val)">
									<el-option v-for="item in floorList" :key="item" :label="item" :value="item" />
								</el-select>
							</div>
						</el-card>
					</div>
				</el-card>
			</div>
			<!-- 分配点位 -->
			<el-divider content-position="left"><span class="text-lg text-bold">{{!!isOnlyExport?'过滤结果':'分配点位'}}</span></el-divider>
			<!-- 分配数量和分配方式 -->
			<el-form ref="distForm" inline :model="distForm" class="form-inline" size="mini" v-show="!isOnlyExport">
				<el-row v-show="!secondFilterForm.is_combo" v-for="pId in (secondFilterForm.point_type_ids || [])" :key="pId">
					<el-form-item :label="'分配总数（'+point_types_map.get(parseInt(pId)).name+'）'">
						<el-input v-model="distForm.all[''+pId]" type="number" @change="(val) => changeDistAll(val, pId)" :min="0" style="width:150px"
						:key="'distFormAll'+pId">
							<template slot="append">个</template>
						</el-input>
					</el-form-item>
					<el-form-item label="未分配数" v-show="(distForm.remain[''+pId] || 0) != 0">
						<span class="text-red text-bold">{{distForm.remain[''+pId]}}个</span>
					</el-form-item>
				</el-row>
				<!-- <row v-for="(c, cIndex) in distForm.combo_all" v-show="!!secondFilterForm.is_combo">
					<el-form-item :label="c.name">
						<el-input v-model="c[cIndex]" type="number" :min="0" style="width:150px">
							<template slot="append">个</template>
						</el-input>
					</el-form-item>
					<el-form-item label="未分配" v-show="distForm.combo_remain[''+c.id] > 0">
						<span class="text-red text-bold">{{distForm.combo_remain[''+c.id]}}个</span>
					</el-form-item>
				</row> -->
				<el-row>
					<el-form-item label="分配方式" prop="dist_type">
						<el-radio-group v-model="distForm.dist_type">
							<el-radio :label="1">平均分配</el-radio>
							<el-radio :label="2" disabled>顺序优先</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-row>
			</el-form>
			<!-- 分配表格 -->
			<div class="flex justify-end align-center flex-no-wrap margin-tb-sm">
				<el-button size="mini" type="primary" plain round @click.native="exportSecondExcel()">导出空位</el-button>
			</div>
			<el-table stripe ref="multipleTable" :data="secondFilterForm.filter_data" tooltip-effect="dark"
				v-loading="secondOriginDataLoading" style="width: 100%" border highlight-current-row row-key="id"
				size="mini" max-height="700px" show-summary :summary-method="getSecondSummaries">
				<el-table-column type="index" label="序号" width="50" fixed="left">
					<template slot-scope="scope">
						<span>{{ scope.$index + 1 }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="name" min-width="120" label="楼盘" fixed="left">
				</el-table-column>
				<el-table-column prop="area" min-width="100" label="区" fixed="left"></el-table-column>

				<el-table-column min-width="100" align="center" :prop="''+pointTypeId"
					v-for="pointTypeId in (secondFilterForm.point_type_ids||[])" :key="pointTypeId">
					<span slot="header">{{point_types_map.get(pointTypeId).name}}</span>
					<template slot-scope="scope">
						<el-input-number v-model="scope.row.to[''+pointTypeId]" :controls="false"
							:max="(((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)" size="mini"
							step-strictly style="width:50%"
							v-if="!isOnlyExport && (((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)>0" 
							 @change="(val, old) => changeDistOne(val, pointTypeId, scope.row, scope.$index)"/>
						<span>
							<span class="margin-left-sm"
								v-if="!isOnlyExport && (((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)>0">/</span>
							<el-button :class="['text-underline','text-bold',{'text-green':(((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)>0}
								,{'text-gray':(((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)==0}]" type="text" size="mini"
								@click.native="onExact(scope.row, scope.$index, pointTypeId)" :disabled="(((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)==0">
								{{(((scope.row.points || [])[''+pointTypeId] || {}).can_count || 0)}}
							</el-button>
						</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="80px" align="center" fixed="right">
					<template slot-scope="scope">
						<el-button icon="el-icon-delete" size="mini" plain type="danger" @click="delSecondRow(scope.$index)" circle></el-button>
					</template>
				</el-table-column>
			</el-table>

			<!-- 确定和取消 -->
			<span slot="footer" class="flex justify-center align-center">
				<el-button class="margin-lr-sm" @click.native="dialogSecondFilter=false" size="mini" v-show="!!isOnlyExport">关 闭</el-button>
				<el-button class="margin-lr-sm" @click.native="dialogSecondFilter=false" size="mini" v-show="!isOnlyExport">取 消</el-button>
				<el-button class="margin-lr-sm" @click.native="confirmDist" size="mini" type="primary" v-show="!isOnlyExport">确 定</el-button>
			</span>
		</el-dialog>
		
		
		<!-- 地图选择 -->
		<PointPlanTencentMap ref="mapChoose" :dateRange.sync="firstFilterForm.date_range" @choose-buildings="mapChoosedBuildings" class="map-dialog"/>
		
		<!-- 地址搜索弹框 -->
		<AddressSearch ref="addressSearch" @choose-addresses="choosedAddresses"
			@close-choose-address="closeAddressChooseDialog" />
		
		<!-- 具体点位可视化弹框 -->
		<exact-view ref="exactView" :exactVisible.sync="exactVisible" :toExact="exactToExact" :viewData="exactToExactViewData"
			:can="exactCan" :total="exactTotal" :key="exactTimer" @choosed="choosedToExact" :leafShowType="2"/>

		<!-- 上传组件，用于初筛上传楼盘表格excel，用于快速选中 -->
		<input class="hiddenUploadInput" type="file" accept="application/vnd.ms-excel" ref="uploadInput"
			@change="handleFile" />
	</div>
</template>

<script>
	import common from '@/utils/common.js';
	import {
		cloneDeep
	} from 'lodash';
	import {
		isArray,
		isObject,
		isTrue,
		isFunction,
		generateUUID,
		accMul,
		accAdd,
		formatDate,
		getTimeSlot,
		getAdcodeListByAdcode,
		compareArrayToGetDiffs,
		obj2Map
	} from '@/utils/util.js';
	import {
		list_all3rd_bycode,
		list_all3rd_bytopcode,
		list_all3rd_bycode_contrain_del_close,
		list_all3rd_bytopcode_contrain_del_close
	} from '@/api/business/setting/dict';
	import {
		area_list, // 根据市id获取所有区
		search_trade_area, // 商圈
		pc_list_all, // 所有省市
		search_address, //腾讯位置服务，地址搜索
		get_base_info_list as get_buildings, // 所有楼盘
		export_building_list_for_point_plan, // 下载楼盘
		upload_building_list_for_point_plan // 上传楼盘
	} from '@/api/business/building/building.js';
	import {
		active_list as active_combos //生效中套餐
	} from '@/api/system/combo';
	import {
		get_company_adcode,
		get_point_type_dis_rule,
		get_company_floors
	} from '@/api/business/building/choose_point.js';
	import {
		first_search
	} from '@/api/business/building/point_plan.js';
	import AddressSearch from '@/components/PointPlanSetting/addressSearch';
	import PointPlanTencentMap from '@/components/PointPlanSetting/pointPlanTencentMap';
	import ExactView from '@/components/TencentMap/ExactView';
	import pointPlanUtil from './js/pointPlanUtil.js';
	import FileSaver from 'file-saver';
	import XLSX from 'xlsx';
	import XLSXS from "xlsx-style"
	export default {
		name: 'PointPlanSettingEditSetting',
		// beforeRouteLeave(to, from, next) {
		// 	this.$destroy();
		// 	next();
		// },
		components: {
			AddressSearch,
			ExactView,
			PointPlanTencentMap
		},
		props: {
			isOnlyExport:{ // 只用作导出
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				floorList: [],
				active_combo_list: [],
				active_combo_map: new Map(),
				point_types: [],
				point_types_map: new Map(),
				buildingAreaList: [],
				buildingAreaMap: new Map(),
				buildingTypes: [],
				tradeAreaAll: [],
				pcAll: [],
				// 当前选中市下的所有区
				areaAll: [],
				industryList: [],
				comboList: [],

				pointRuleObj: {},
				activeRuleMap: new Map(),
				loadingRules: false,
				
				buildingDisObjMap: new Map(),

				dialogFirstLoading: false,
				dialogFirstFilter: false,
				firstFilterForm: {
					type_ids: [],
					is_combo: false,
					combo_ids: [],
					point_type_ids: [],
					date_range: [formatDate(new Date()) + ' 00:00:00', formatDate(new Date()) + ' 23:59:59'],
					is_building_circle: false,
					building_area_ids: [],
					pca: [],
					adcodes: [],
					address: null,
					trade_area_selected: [],
					building_circle: {
						lng: null,
						lat: null,
						radius: 1000
					},
					address_circle_locations: [],
					address_circle: {
						lng: null,
						lat: null,
						radius: 1000
					},
					business_circle: {
						lat: null,
						lng: null,
						radius: 1000
					},
					industry_id: null,
					price_range: {
						min: null,
						max: null
					},
					result_point_type_ids: [], // 初筛结果返回，套餐会转换为点位类型ids
					
					outBuildingIds:[], // 排斥的楼盘ids
					inBuildingIds:[], // 包含的楼盘ids
					outPointIds:[], // 排斥的点位ids
					inPointIds:[], // 包含的点位ids
				},
				firstFilterFormRules: {
					point_type_ids: [{
						required: true,
						message: '请选择点位类型',
						trigger: 'change'
					}]
				},

				firstResults: [],
				firstResultsSum: {},
				firstResultsColShow: {},
				firstResultsLoading: false,


				dialogSecondLoading: false,
				dialogSecondFilter: false,
				secondOriginDataLoading: false,
				secondFilterForm: {
					is_combo: false,
					point_type_ids: [],
					combo_ids: [],
					origin_data: [],
					filter_data: [],
					filter_data_sum: {
						to: {},
						can_count: {},
						to_exact: {},
						exact_list: {},
					},
					date_range: [formatDate(new Date()) + ' 00:00:00', formatDate(new Date()) + ' 23:59:59'],
				},
				distForm: {
					all: {},
					dist_type: 1,
					remain: {},
					combo_all: [],
					combo_remain: {},
				},

				exactVisible: false,
				exactToExact: [],
				exactToExactViewData: [],
				exactTotal: 0,
				exactCan: 0,
				exactTimer: '',
			}
		},
		mounted() {
			this.getAddPrevData();
		},
		methods: {
			// 初始化
			getAddPrevData() {
				const that = this;
				that.dialogFirstLoading = true;
				Promise.all([
					that.getCompanyAdcode(),
					that.getAllBuildings(),
					that.getBuildingTypes(),
					that.getCompanyFloors(),
					that.getIndustryList(),
					that.getPointTypes(),
					that.getActiveCombos()
				]).then(arr => {
					that.dialogFirstLoading = false;
				});
			},
			// 下载楼盘
			downloadBuildings() {
				const that = this;
				export_building_list_for_point_plan({
					start_at: that.firstFilterForm.date_range[0],
					end_at: that.firstFilterForm.date_range[1]
				})
			},
			// 上传楼盘excel，用于快速选中
			uploadBuildings() {
				const that = this;
				that.$refs.uploadInput.click();
			},
			// 上传楼盘
			handleFile(e) {
				let loading = common.showLoading({
					text: '上传中...'
				})
				const that = this
				let files = e.target.files;
				let uploadData = new FormData()
				let file = files[files.length - 1]

				// 限制2M以内
				if (file.size / (Math.pow(1024, 2)) > 2) {
					this.$notify.error({
						title: "错误",
						message: "不能上传大小超过2MB"
					});
				} else {
					uploadData.append('file', file);
				}
				return upload_building_list_for_point_plan(uploadData)
					.then(({
						data
					}) => {
						loading.close()
						if (data) {
							that.handleUploadBuildings(data);
						} else {
							common.messageError('上传失败!')
						}
					})
					.catch(() => {
						loading.close()
					})
			},
			// 处理上传的楼盘，快速选中
			handleUploadBuildings(choosed) {
				const that = this;
				let ids = JSON.parse(JSON.stringify(that.firstFilterForm.building_area_ids));
				let buildingMap = new Map();
				(that.buildingAreaList || []).forEach(d => {
					buildingMap.set(d.name, d);
				});
				(choosed || []).forEach(c => {
					const d = buildingMap.get(c.name);
					if (!!d && ids.indexOf(parseInt(d.id)) == -1) {
						ids.push(parseInt(d.id));
					}
				});
				that.$set(that.firstFilterForm, 'building_area_ids', ids);
			},
			// 获取公司所有楼层
			getCompanyFloors() {
				const that = this;
				return get_company_floors()
					.then(({
						data
					}) => {
						that.floorList = data;
					});
			},
			// 获取社区分类
			getBuildingTypes() {
				const that = this
				return list_all3rd_bycode({
						code: "lpxg-sqfl"
					})
					.then(res => {
						const {
							code,
							data
						} = res
						if (code == 200) {
							that.buildingTypes = data
						}
					})
			},
			// 获取所有套餐
			getActiveCombos() {
				const that = this
				return active_combos()
					.then(({
						data
					}) => {
						if (data.length > 0) {
							that.active_combo_list = data
							that.active_combo_map = new Map()
							data.forEach(d => {
								that.active_combo_map.set(parseInt(d.id), d)
							})
						}
					})
			},
			// 获取所有省市
			getPCListAll() {
				const that = this
				return new Promise((resolve, reject) => {
					pc_list_all()
						.then(res => {
							const {
								code,
								data
							} = res
							if (code == 200) {
								if (data && data.length > 0) {
									that.pcAll = data
									resolve()
								}
							}
						})
				})

			},
			// 楼盘列表
			getAllBuildings() {
				return get_buildings().then(res => {
					this.buildingAreaList = res.data;
					this.buildingAreaMap = new Map();
					(res.data || []).map(d => {
						this.buildingAreaMap.set(d.id, d);
					});
				})
			},
			// 获取行业list
			getIndustryList() {
				return list_all3rd_bycode_contrain_del_close({
						code: "khxg-hy"
					})
					.then(res => {
						this.industryList = res.data;
					})
			},
			// 获取商圈列表
			getTradeAreas(adcode, lat, lng) {
				const that = this
				return search_trade_area({
						boundary: adcode,
						lat: lat,
						lng: lng
					})
					.then(({
						data
					}) => {
						that.tradeAreaAll = data || []
					})
			},
			// 获取公司主营城市
			async getCompanyAdcode() {
				const that = this;
				await that.getPCListAll();
				return get_company_adcode()
					.then(({
						data: {
							adcode,
							lat,
							lng
						}
					}) => {
						let pca = getAdcodeListByAdcode(adcode);
						that.firstFilterForm.pca = pca;
						that.getAreaList(pca[pca.length - 1]);
						that.getTradeAreas(pca[pca.length - 1], lat, lng);
					});
			},
			// 查询地址
			async searchAddress() {
				const that = this

				if (!that.firstFilterForm.pca || that.firstFilterForm.pca.length == 0) {
					common.message({
						message: '请选择省市',
						type: 'error'
					})
					return false
				}
				if (!that.firstFilterForm.address) {
					common.message({
						message: '请输入地址',
						type: 'error'
					})
					return false
				}

				that.$refs.addressSearch.searchAddressList({
					keyword: that.firstFilterForm.address,
					boundary: that.firstFilterForm.pca[that.firstFilterForm.pca.length - 1]
				})
			},
			// 关闭搜索地址框
			closeAddressChooseDialog() {
				const that = this;
				//that.firstFilterForm.address = null;
			},
			// 选中搜索地址
			choosedAddress({
				lat,
				lng
			}) {
				const that = this;
				if (!!lat && !!lng) {
					that.firstFilterForm.address_circle.lat = lat;
					that.firstFilterForm.address_circle.lng = lng;
				}
			},
			// 选中搜索地址（多个）
			choosedAddresses(locations) {
				const that = this;
				//console.log('locations2',locations);
				//that.firstFilterForm.address_circle_locations = [];
				let hasMap = new Map();
				(that.firstFilterForm.address_circle_locations || []).forEach((data) => {
					hasMap.set(data.id, true);
				});
				(locations || []).forEach((data) => {
					if (!hasMap.get(data.id)) that.firstFilterForm.address_circle_locations.push(data);
				});
			},
			// 关闭地址tag
			closeAddressTag(index) {
				const that = this;
				that.firstFilterForm.address_circle_locations.splice(index, 1);
			},
			// 打开地图选择
			openMapChoose(){
				const that = this;
				that.$refs.mapChoose.showMapDialog();
			},
			// 地图选中楼盘
			mapChoosedBuildings(buildings){
				const that = this;
				let buildingSet = new Set();
				(that.firstFilterForm.building_area_ids || []).forEach(id => {
					const _id = parseInt(id);
					buildingSet.add(_id);
				});
				(buildings || []).forEach(({id, dis_obj}) => {
					const _id = parseInt(id);
					if(!buildingSet.has(_id)) {
						that.firstFilterForm.building_area_ids.push(_id);
					}
					that.buildingDisObjMap.set(_id, dis_obj);
				});
			},
			// 改变是否套餐
			changeIsCombo(val, isSet) {
				const that = this;
				if (!!isSet) {
					that.firstFilterForm.is_combo = !!val;
				}
				if (!that.firstFilterForm.is_combo) {
					that.firstFilterFormRules = {
						point_type_ids: [{
							required: true,
							message: '请选择一种点位类型',
							trigger: 'change'
						}]
					};
				} else {
					that.firstFilterFormRules = {
						combo_ids: [{
							required: true,
							message: '请至少选择一个套餐',
							trigger: 'change'
						}]
					};
				}
				that.$refs.firstFilterForm.clearValidate()
				that.firstResults = [];
				that.firstResultsSum = {};
				that.firstFilterForm.result_point_type_ids = [];
			},
			// 改变省市
			changeCity(val) {
				const that = this
				const code = val[val.length - 1]
				that.getAreaList(code).then(() => {
					that.firstFilterForm.adcodes = [];
				});
			},
			// 获取pid下所有区
			getAreaList(pid) {
				const that = this
				return area_list({
						pid: pid
					})
					.then(({
						data
					}) => {
						that.areaAll = data
					})
			},
			// 点位类型列表
			getPointTypes() {
				const that = this
				return list_all3rd_bytopcode({
						code: 'dwxg'
					})
					.then(res => {
						const {
							code,
							data
						} = res
						if (code == 200) {
							that.point_types = data
							if ((that.point_types || []).length == 1) {
								that.firstFilterForm.point_type_ids = [that.point_types[0].id];
							}
							if (!that.point_types_map) that.point_types_map = new Map();
							(that.point_types || []).forEach(p => {
								that.point_types_map.set(parseInt(p.id), p);
							})
						}
					})
			},
			// 改变点位类型
			changePointType() {
				const that = this;
				if ((that.firstFilterForm.point_type_ids || []).length > 0) {} else {
					that.firstResults = [];
					that.firstResultsSum = {};
					that.firstFilterForm.result_point_type_ids = [];
					that.handleRule();
				}
			},

			// 关闭弹窗
			dialogCUClose(formName) {
				const that = this
				switch (formName) {
					case 'firstFilterForm':
						that.$refs.firstFilterForm.clearValidate()
						that.resetFirstFilterForm()
						// that.buildingDisObjMap = new Map()
						break;
				}
			},
			// 提交
			searchSubmit(formName) {
				const that = this;
				switch (formName) {
					case 'firstFilterForm':
						that.searchFirst();
						break;
				}

			},
			// 初筛
			searchFirst() {
				const that = this;
				const formData = JSON.parse(JSON.stringify(that.firstFilterForm));
				let params = {};

				if (!!that.firstFilterForm.is_combo) {
					if ((formData.combo_ids || []).length <= 0) {
						common.messageError('请选择套餐！');
						return false;
					}
				} else {
					if ((formData.point_type_ids || []).length <= 0) {
						common.messageError('请选择点位类型！');
						return false;
					}
				}
				that.firstResultsLoading = true;
				// 时间段
				params.date_range = {
					start_at: formData.date_range[0],
					end_at: formData.date_range[1]
				};
				// 行政区划
				if ((formData.adcodes || []).length > 0) params.adcodes = formData.adcodes;
				// 搜索地址辐射
				if ((formData.address_circle_locations || []).length > 0) {
					params.address_locations = formData.address_circle_locations.map(b => {
						return {
							id: b.id,
							title: b.title,
							location: b.location,
						};
					});
					params.address_radius = formData.address_circle.radius || 0;
				}
				// 楼盘
				if (!!formData.is_building_circle) { // 是楼盘辐射
					if ((formData.building_area_ids || []).length > 0) {
						params.building_locations = formData.building_area_ids.map(bId => {
							const b = that.buildingAreaMap.get(bId);
							return {
								lat: b.lat,
								lng: b.lng
							}
						});
						params.building_radius = formData.building_circle.radius || 0;
					}
				} else { // 不是楼盘辐射
					if ((formData.building_area_ids || []).length > 0) {
						params.building_ids = formData.building_area_ids;
					}
				}
				// 商圈辐射
				if ((formData.trade_area_selected || []).length > 0) {
					params.business_locations = formData.trade_area_selected.map(b => {
						return {
							id: b.id,
							title: b.title,
							location: b.location,
						};
					});
					params.business_radius = formData.business_circle.radius || 0;
				}
				// 楼盘类型
				if ((formData.building_type_ids || []).length > 0) {
					params.building_type_ids = formData.building_type_ids;
				}
				// 投放行业
				if (!!formData.industry_id) {
					params.industry_id = formData.industry_id;
				}
				// 楼盘均价范围
				if (!!formData.price_range.min || !!formData.price_range.max) {
					params.price_range = {};
					if (!!formData.price_range.min) {
						params.price_range.min = formData.price_range.min;
					}
					if (!!formData.price_range.max) {
						params.price_range.max = formData.price_range.max;
					}
				}
				// 点位类型 或 套餐
				if (!!that.firstFilterForm.is_combo) {
					if ((formData.combo_ids || []).length > 0) {
						params.combo_ids = formData.combo_ids;
					}
				} else {
					if ((formData.point_type_ids || []).length > 0) {
						params.point_type_ids = formData.point_type_ids;
					}
				}
				
				if((formData.outBuildingIds || []).length > 0){
					params.building_ids_out = formData.outBuildingIds;
				}
				if((formData.inBuildingIds || []).length > 0){
					params.building_ids_in = formData.inBuildingIds;
				}
				if((formData.outPointIds || []).length > 0){
					params.device_ids_out = formData.outPointIds;
				}
				if((formData.inPointIds || []).length > 0){
					params.device_ids_in = formData.inPointIds;
				}

				console.log(params);

				first_search(params)
					.then(({
						data: {
							buildings,
							dis_obj_map,
							point_type_ids
						}
					}) => {
						that.handleFirstResults(buildings || []);
						that.firstFilterForm.result_point_type_ids = point_type_ids || [];
						(obj2Map(dis_obj_map || {}, true) || new Map()).forEach(function (value, key, map) {
							const old_dis_obj = (that.buildingDisObjMap || new Map()).get(parseInt(key)) || null;
							let flag = false;
							if(!!old_dis_obj){
								const cur_dis = parseFloat(value.dis || 0);
								const old_dis = parseFloat(old_dis_obj.dis || 0);
								if(cur_dis < old_dis){
									flag = true;
								}
							}else{
								flag = true;
							}
							if(!!flag) that.buildingDisObjMap.set(parseInt(key), cloneDeep(value));
						});
						that.firstResultsLoading = false;
					});

			},
			// 处理初筛数据
			handleFirstResults(buildings) {
				const that = this;
				that.firstResultsSum = {};
				that.firstResults = [];
				let data = (buildings || []).map(b => {
					let deviceCount = 0;
					for (const p of Object.keys(b.points || {})) {
						if (!!p) {
							const all_count = b.points['' + p].all_count || 0;
							const used_count = (b.points['' + p].used_devices || []).length;
							const lock_count = (b.points['' + p].lock_devices || []).length;
							const can_count = (b.points['' + p].can_devices || []).length;
							deviceCount += all_count;

							that.firstResultsSum.all = (that.firstResultsSum.all || 0) + all_count;
							that.firstResultsSum[p + '_all'] = (that.firstResultsSum[p + '_all'] || 0) +
								all_count;
							that.firstResultsSum[p + '_used'] = (that.firstResultsSum[p + '_used'] || 0) +
								used_count;
							that.firstResultsSum[p + '_lock'] = (that.firstResultsSum[p + '_lock'] || 0) +
								lock_count;
							that.firstResultsSum[p + '_can'] = (that.firstResultsSum[p + '_can'] || 0) + can_count;
						}
					}
					for (const p of Object.keys(b.preset_point_counts || {})) {
						if (!!p) {
							const preset_count = b.preset_point_counts['' + p] || 0;
							that.firstResultsSum[p + '_preset'] = (that.firstResultsSum[p + '_preset'] || 0) +
								preset_count;
						}
					}
					b.has_device = (deviceCount > 0);

					return b;
				});
				data.sort((a, b) => {
					return (!!a.has_device?0:1) - (!!b.has_device?0:1)
				})
				that.firstResults = data;
			},
			// 重置初筛选项
			searchReset(formName) {
				const that = this;
				switch (formName) {
					case 'firstFilterForm':
						that.resetFirstFilterForm();
						that.$refs.firstFilterForm.resetFields();
						break;
				}
			},
			// 置空初筛条件
			resetFirstFilterForm() {
				const that = this;
				that.firstFilterForm = Object.assign({}, that.firstFilterForm, {
					type_ids: [],
					is_combo: false,
					combo_ids: [],
					point_type_ids: [],
					is_building_circle: false,
					building_area_ids: [],
					adcodes: [],
					address: null,
					trade_area_selected: [],
					building_circle: {
						lng: null,
						lat: null,
						radius: 1000
					},
					address_circle_locations: [],
					address_circle: {
						lng: null,
						lat: null,
						radius: 1000
					},
					business_circle: {
						lat: null,
						lng: null,
						radius: 1000
					},
					industry_id: null,
					price_range: {
						min: null,
						max: null
					},
					result_point_type_ids: [],
					outBuildingIds:[], // 排斥的楼盘ids
					inBuildingIds:[], // 包含的楼盘ids
					outPointIds:[], // 排斥的点位ids
					inPointIds:[], // 包含的点位ids
				});
				that.firstResults = [];
				that.firstResultsSum = {};
			},
			// 初筛合计行方法
			getFirstSummaries({
				columns,
				data
			}) {
				const that = this;
				const sums = [];
				const maxC = (columns || []).length;
				columns.forEach((column, index) => {
					if (index === 0) {
						sums[index] = '合计';
						return;
					} else if (index > 2 && index < (maxC - 1)) {
						if (!!that.firstResultsSum[column.property]) {
							sums[index] = that.firstResultsSum[column.property] || 0;
						} else {
							sums[index] = 0;
						}
						return;
					} else {
						sums[index] = '';
						return;
					}
				});
				return sums;
			},
			//初筛 标记无已安装设备行
			getFirstRowClassName({
				row,
				rowIndex
			}) {
				const that = this;
				if (!!row.has_device) {
					return '';
				} else {
					return 'no-device-building';
				}
				return '';
			},
			//初筛 标记空闲列
			getFirstCellClassName({
				row,
				column,
				rowIndex,
				columnIndex
			}) {
				const that = this;
				if ((column.property || '').indexOf('_can') > -1) return 'can-num';
				return '';
			},
			// 删除初筛楼盘
			async delFirstBuilding(index) {
				const that = this;
				const confirm = await common.confirmDialog('您确定要删除该楼盘？');
				if (!!confirm) {
					that.firstResults.splice(index, 1);
					that.handleFirstResults(that.firstResults);
				}
			},
			// 选择时间段的回调
			showAdd({dateRange, outBuildingIds, inBuildingIds, outPointIds, inPointIds, point_type_ids, building_area_ids}) {
				const that = this;
				//console.log('dateRange2',dateRange);
				if (!!dateRange) that.firstFilterForm.date_range = JSON.parse(JSON.stringify(dateRange));
				if (!!outBuildingIds) that.firstFilterForm.outBuildingIds = outBuildingIds || [];
				if (!!inBuildingIds) that.firstFilterForm.inBuildingIds = inBuildingIds || [];
				if (!!outPointIds) that.firstFilterForm.outPointIds = outPointIds || [];
				if (!!inPointIds) that.firstFilterForm.inPointIds = inPointIds || [];
				if (!!point_type_ids) that.firstFilterForm.point_type_ids = point_type_ids || [];
				if (!!building_area_ids) that.firstFilterForm.building_area_ids = building_area_ids || [];
				that.dialogFirstFilter = true;
			},
			
			// 将数据转换
			toJsonWithTitles(params) {
				if (!params) return [];
				    var titles = params.titles;
				    var datas = params.datas;
							
				    var i = 0, length = datas.length, data;
				    var _datas = [];
				    for (i; i < length; i++) {
				        data = datas[i];
				        var key;
				        var _data = {}
				        for (key in titles) {
				            _data[key] = data[titles[key]]
				        }
				        _datas.push(_data);
				    }
				    return _datas;
			},
			// 导出初筛表格
			exportFirstExcel(){
				const that = this;
				
				let pMerges = [], pTitle = [], pTitleType=[];// 标题
				let contents = [];// 楼盘点位
				let sum = [];// 合计
				
				(that.firstFilterForm.result_point_type_ids || []).forEach((pId, pIndex) => {
					pMerges.push({s: {r: 0, c: 9+(pIndex*5)}, e: {r: 0, c: 13+(pIndex*5)}});
					pTitle = [...pTitle, that.point_types_map.get(parseInt(pId)).name, null, null, null, null];
					pTitleType = [...pTitleType, '预设', '已装', '上刊', '锁定', '空闲'];
					sum = [...sum, that.firstResultsSum[''+pId+'_preset']||0, that.firstResultsSum[''+pId+'_all']||0
					, that.firstResultsSum[''+pId+'_used']||0, that.firstResultsSum[''+pId+'_lock']||0, that.firstResultsSum[''+pId+'_can']||0];
				});
				
				const datas = JSON.parse(JSON.stringify((that.firstResults || []).filter(data => (!!data.has_device))));
				datas.sort((a,b) => (a.area.localeCompare(b.area)));
				datas.forEach((data, index) => {
					const building = that.buildingAreaMap.get(parseInt(data.id));
					const disObj = that.buildingDisObjMap.get(parseInt(data.id)) || null;
					let content = [(index+1), data.area, data.name
					, building.address||null, building.type_name||null, building.price||null
					, building.scale||null, building.occupancy_rate||null, building.audience_name_str||null];
					(that.firstFilterForm.result_point_type_ids || []).forEach((pId, pIndex) => {
						const can_devices = (((data.points || {})[''+pId] || {}).can_devices || []);
						content.push(data.preset_point_counts[''+pId] || 0);
						content.push(((data.points || {})[''+pId] || {}).all_count || 0);
						content.push((((data.points || {})[''+pId] || {}).used_devices || []).length);
						content.push((((data.points || {})[''+pId] || {}).lock_devices || []).length);
						content.push(can_devices.length);
					});
					if(!!disObj && !!disObj.title){
						content.push('距离\"'+disObj.title+'\"'+parseFloat(disObj.dis).toFixed(0)+'米');
					}else{
						content.push(null);
					}
					contents.push(content);
				});
				
				const sumMerges = {s: {r: 2+contents.length, c: 0}, e: {r: 2+contents.length, c: 8}};
				
				var aoa1 = [
					['序号', '区', '楼盘', '地址', '分类', '均价', '居住规模(人)', '入住率(%)', '受众描述', ...pTitle, '备注'],
					[null, null, null,null, null, null,null, null, null, ...pTitleType, null],
					...contents,
					['合计', null, null,null, null, null,null, null, null, ...sum, null]
				];
				var sheet1 = XLSX.utils.aoa_to_sheet(aoa1);
				sheet1['!merges'] = [
					{s: {r: 0, c: 0}, e: {r: 1, c: 0}},
					{s: {r: 0, c: 1}, e: {r: 1, c: 1}},
					{s: {r: 0, c: 2}, e: {r: 1, c: 2}},
					{s: {r: 0, c: 3}, e: {r: 1, c: 3}},
					{s: {r: 0, c: 4}, e: {r: 1, c: 4}},
					{s: {r: 0, c: 5}, e: {r: 1, c: 5}},
					{s: {r: 0, c: 6}, e: {r: 1, c: 6}},
					{s: {r: 0, c: 7}, e: {r: 1, c: 7}},
					{s: {r: 0, c: 8}, e: {r: 1, c: 8}},
					{s: {r: 0, c: 9+(pTitleType.length || 0)}, e: {r: 1, c: 9+(pTitleType.length || 0)}},
					...pMerges,
					sumMerges
				];
				
				const sheet_name = that.firstFilterForm.date_range[0].substring(0, 10)+' ~ '+that.firstFilterForm.date_range[1].substring(0, 10);
				let wb = { //定义操作文档
				    SheetNames:[sheet_name], //定义表明
				    Sheets:{},
				}
				wb.Sheets[''+sheet_name] = Object.assign({}, sheet1);
				
				var wbout = XLSX.write(wb, {
					bookType: 'xlsx',
					bookSST: true,
					type: 'array'
				})
				
				try {
					FileSaver.saveAs(new Blob([wbout], {
						type: 'application/octet-stream'
					}), '空位导出.xlsx')
				} catch (e) {
					if (typeof console !== 'undefined') {
						console.log(e, wbout)
					}
				}
				return wbout
			},
			// 导出分配表格
			exportSecondExcel(){
				const that = this;
				
				let pTitle = [];// 标题
				let contents = [];// 楼盘点位
				let sum = [];// 合计
				
				(that.secondFilterForm.point_type_ids || []).forEach((pId, pIndex) => {
					pTitle.push(that.point_types_map.get(parseInt(pId)).name);
					sum.push((that.secondFilterForm.filter_data_sum.can_count || {})[''+pId] || 0);
				});
				
				const datas = JSON.parse(JSON.stringify(that.secondFilterForm.filter_data || []));
				datas.sort((a,b) => (a.area.localeCompare(b.area)));
				datas.forEach((data, index) => {
					const building = that.buildingAreaMap.get(parseInt(data.id));
					const disObj = that.buildingDisObjMap.get(parseInt(data.id)) || null;
					let content = [(index+1), data.area, data.name
					, building.address||null, building.type_name||null, building.price||null
					, building.scale||null, building.occupancy_rate||null, building.audience_name_str||null];
					let b_sum_count = 0;
					(that.secondFilterForm.point_type_ids || []).forEach((pId, pIndex) => {
						const can_count = parseInt(((data.points || {})[''+pId] || {}).can_count || 0);
						content.push(can_count);
						b_sum_count += can_count;
					});
					if(!!disObj && !!disObj.title){
						content.push('距离\"'+disObj.title+'\"'+parseFloat(disObj.dis).toFixed(0)+'米');
					}else{
						content.push(null);
					}
					if(b_sum_count > 0) contents.push(content);
				});
				
				const sumMerges = {s: {r: 1+contents.length, c: 0}, e: {r: 1+contents.length, c: 8}};
				
				var aoa1 = [
					['序号', '区', '楼盘', '地址', '分类', '均价', '居住规模(人)', '入住率(%)', '受众描述', ...pTitle, '备注'],
					...contents,
					['合计', null, null,null, null, null,null, null, null, ...sum, null]
				];
				var sheet1 = XLSX.utils.aoa_to_sheet(aoa1);
				sheet1['!merges'] = [
					sumMerges
				];
				
				const sheet_name = that.secondFilterForm.date_range[0].substring(0, 10)+' ~ '+that.secondFilterForm.date_range[1].substring(0, 10);
				let wb = { //定义操作文档
				    SheetNames:[sheet_name], //定义表明
				    Sheets:{},
				}
				wb.Sheets[''+sheet_name] = Object.assign({}, sheet1);
				
				var wbout = XLSX.write(wb, {
					bookType: 'xlsx',
					bookSST: true,
					type: 'array'
				})
				
				try {
					FileSaver.saveAs(new Blob([wbout], {
						type: 'application/octet-stream'
					}), '空位导出.xlsx')
				} catch (e) {
					if (typeof console !== 'undefined') {
						console.log(e, wbout)
					}
				}
				return wbout
			},

			// 改变规则开关
			changRuleSwitch(pId, ruleId, val) {
				const that = this;
				// A面、B面、AB面，3种规则互斥
				if (!!val && (ruleId == 4 || ruleId == 5 || ruleId == 6)) {
					(that.pointRuleObj[''+pId].rules || []).forEach((r, i) => {
						if (r.id == 4 || r.id == 5 || r.id == 6) {
							that.pointRuleObj[''+pId].rules[i].on = r.id == ruleId;
						}
					});
				}
				that.handleRule();
			},
			// 改变规则数量
			changRuleN(pId, ruleId, val) {
				const that = this;
				that.handleRule();
			},
			// 改变规则指定楼层
			changeRuleAppoint(pId, ruleId, val) {
				const that = this;
				((that.pointRuleObj['' + pId] || {}).rules || []).forEach((r, i) => {
					if (r.id == ruleId) {
						that.pointRuleObj['' + pId].rules[i].on = (val || []).length > 0;
					}
				});
				that.handleRule();
			},
			// 处理规则改变
			handleRule() {
				const that = this;
				that.getCurActiveRule();
				that.filterDistTableData();
			},
			// 设置当前启用的过滤规则
			getCurActiveRule() {
				const that = this;
				that.activeRuleMap = new Map();
				let activeMap = new Map();
				const pIds = Object.keys(that.pointRuleObj);
				(pIds || []).forEach(pId => {
					let activePMap = activeMap.get('' + pId) || new Map();
					(that.pointRuleObj['' + pId].rules || []).forEach(r => {
						if (!!r.on) {
							activePMap.set('' + r.id, r);
						}
					});
					activeMap.set('' + pId, activePMap);
				});
				that.activeRuleMap = activeMap;
				that.pointRuleObj = Object.assign({}, that.pointRuleObj);
			},
			// 根据设备生成key
			generateDeviceKey(device){
				const buildingkey = '' + (device.building_number!=null?device.building_number:'');
				const unitKey = buildingkey + '_' + (device.unit_number!=null?device.building_number:'');
				const floorKey = unitKey + '_' + (device.floor!=null?device.building_number:'');
				const doorKey = floorKey + '_' + (device.door_number!=null?device.door_number:'');
				const railKey = doorKey + '_' + (device.rail_number!=null?device.rail_number:'');
				return {
					buildingkey,
					unitKey,
					floorKey,
					doorKey,
					railKey
				}
			},
			// 根据启用的规则，过滤点位
			filterDistTableData() {
				const that = this;
				if (that.activeRuleMap.size > 0) {
					that.$set(that.secondFilterForm, 'filter_data', that.secondFilterForm.origin_data
						.map(item => {
							let row = JSON.parse(JSON.stringify(item));
							const pIds = Object.keys(row.points) || [];
							if (pIds.length > 0) {
								pIds.forEach(pId => {
									const can_devices = row.points['' + pId].can_devices || [];
									const ruleMap = that.activeRuleMap.get('' + pId) || new Map();
									if (can_devices.length > 0 && ruleMap.size > 0) {
										let min=0;
										let ruleLimitList = [];
										
										let unitMap = new Map();
										let AMap = new Map();
										let BMap = new Map();
										let ABMap = new Map();
										let D7List = [];
										
										can_devices.forEach(device => {
											const {unitKey, doorKey, railKey} = that.generateDeviceKey(device);
											if(''+pId==='122' || ''+pId==='123' || ''+pId==='125' || ''+pId==='129') {
												if(!!unitKey){
													let floorMap = unitMap.get(unitKey) || new Map();
													if(!!device.floor){
														const floor = ''+device.floor;
														let list = floorMap.get(floor) || [];
														list.push(device);
														floorMap.set(floor, list);
													}
													unitMap.set(unitKey, floorMap);
												}
											}
											if(''+pId==='127' || ''+pId==='128' || ''+pId==='135'){
												if((device.media_feature || '').indexOf('A面') > -1){
													if(!!railKey){
														let list = AMap.get(railKey) || [];
														list.push(device);
														AMap.set(railKey, list);
													}
												}
												if((device.media_feature || '').indexOf('B面') > -1){
													if(!!railKey){
														let list = BMap.get(railKey) || [];
														list.push(device);
														BMap.set(railKey, list);
													}
												}
											}
										});
										if(AMap.size > 0 && BMap.size > 0){
											AMap.forEach(function(aList,key){
												if(aList.length > 0){
													const bList = BMap.get(key) || [];
													if(bList.length > 0){
														ABMap.set(key, {
															a: aList[0],
															b: bList[0]
														});
													}
												}
											});
										}
										// 过滤
										ruleMap.forEach(function(rule, ruleId) {
											if ('' + ruleId === '1') { // 一小区n个
												ruleLimitList.push(Math.min(can_devices.length, parseInt(rule
													.n || 0)));
											}
											if ('' + ruleId === '2') { // 一单元n个
												let resultCount = 0;
												let limitCount = parseInt(rule.n || 0);
												for (let floorMap of unitMap.values()) {
													let c = 0;
													for (let ds of floorMap.values()) {
														c += ds.length || 0;
													}
													resultCount += (c < limitCount ? c : limitCount);
												}
												ruleLimitList.push(resultCount);
											}
											if ('' + ruleId === '3') { // 一层1个
												let resultCount = 0;
												for (let floorMap of unitMap.values()) {
													resultCount += (floorMap.size || 0);
												}
												ruleLimitList.push(resultCount);
											}
											if ('' + ruleId === '4') { // A面
												let resultCount = AMap.size || 0;
												ruleLimitList.push(resultCount);
											}
											if ('' + ruleId === '5') { // B面
												let resultCount = BMap.size || 0;
												ruleLimitList.push(resultCount);
											}
											if ('' + ruleId === '6') { // A面+B面
												let resultCount = ABMap.size || 0;
												ruleLimitList.push(resultCount * 2);
											}
											if ('' + ruleId === '7') { // 指定楼层
												let resultCount = 0;
												let can = 0;
												let limitFloors = (rule.appoint || []).map(a => ('' + a));
												for (let floorMap of unitMap.values()) {
													let unitCan = 0;
													const unitLimit = parseInt((ruleMap.get('2') || new Map()).n || -1);
													for (let ds of floorMap.values()) {
														let temp = (ds || []).filter(d => (limitFloors
															.indexOf('' + d.floor) > -1));
														if(temp.length>0){
															if(!!ruleMap.get('3')) {
																if(unitLimit == -1){
																	can++;
																}else{
																	if(unitCan < unitLimit){
																		can++;
																		unitCan++;
																	}
																}
															}else{
																if(unitLimit == -1){
																	can+=temp.length;
																}else{
																	if(unitCan < unitLimit){
																		if((unitCan+temp.length) <= unitLimit){
																			can+=temp.length;
																			unitCan+=temp.length;
																		}else{
																			const sub = (unitCan+temp.length) - unitLimit;
																			can+=sub;
																			unitCan+=sub;
																		}
																	}
																}
															}
														}
														D7List.push(...temp);
													}
												}
												resultCount = can;
												ruleLimitList.push(resultCount);
											}
										});
										//console.log(row.name, pId, ruleLimitList);
										row.points['' + pId].can_count = Math.min(row.points['' + pId].can_count || 0, ...ruleLimitList);
										row.points['' + pId].unitMap = unitMap;
										row.points['' + pId].AMap = AMap;
										row.points['' + pId].BMap = BMap;
										row.points['' + pId].ABMap = ABMap;
										row.points['' + pId].D7List = D7List;
										
										
									}
								});
							}
							//console.log(row);
							return row;
						}));
				} else {
					that.$set(that.secondFilterForm, 'filter_data', JSON.parse(JSON.stringify(that.secondFilterForm
						.origin_data)));
				}
				that.secondFilterForm.point_type_ids.forEach(id => {
					that.$set(that.distForm.all, ''+id, 0);
					that.$set(that.distForm.remain, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.to, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.can_count, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.to_exact, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.exact_list, ''+id, []);
				});
				that.calChoosedSum();
			},
			// 获取点位规则
			getPointRules(point_type_ids) {
				const that = this;
				that.loadingRules = true;
				return get_point_type_dis_rule({
						ids: (point_type_ids || [])
					})
					.then(({
						data
					}) => {
						if ((data || []).length > 0) {
							data.forEach(pRule => {
								if (!!pRule.rules) pRule.rules.forEach(r => {
									r.on = false;
									r.n = 1;
									r.appoint = [];
								});
								that.$set(that.pointRuleObj, '' + pRule.id, pRule);
							})
						}
						that.loadingRules = false;
					})
					.catch(() => {
						that.loadingRules = false;
					})
			},

			// 分配点位，打开点位分配弹框，关闭初筛弹框
			async toSecondFilter() {
				const that = this;

				// todo 增加确认弹框

				const loading = common.showLoading();
				that.secondFilterForm.is_combo = !!that.firstFilterForm.is_combo;
				that.secondFilterForm.date_range = JSON.parse(JSON.stringify(that.firstFilterForm.date_range));
				that.secondFilterForm.point_type_ids = JSON.parse(JSON.stringify(that.firstFilterForm
					.result_point_type_ids || []));
				that.secondFilterForm.combo_ids = JSON.parse(JSON.stringify(that.firstFilterForm.combo_ids || []));
				let origin_data = JSON.parse(JSON.stringify(that.firstResults || [])).filter(d => {
					//return d.has_device;
					let flag = false;
					const keys = Object.keys(d.points) || [];
					keys.forEach(key => {
						flag = flag || ((d.points[key].can_devices || []).length > 0);
					})
					return flag;
				}).map(d => {
					d.to = {};
					d.combo_to = {};
					d.to_exact = {};
					that.secondFilterForm.point_type_ids.forEach(id => {
						d.to['' + id] = 0;
						d.to_exact['' + id] = [];
					});
					that.secondFilterForm.combo_ids.forEach(id => {
						d.combo_to['' + id] = 0;
					});
					// 设置可分配数，可以由规则变换
					const pIds = Object.keys(d.points || {}) || [];
					pIds.forEach(pId => {
						d.points['' + pId].can_count = (d.points['' + pId].can_devices || []).length;
					});
					return d;
				});
				that.secondFilterForm.point_type_ids.forEach(id => {
					that.$set(that.distForm.all, ''+id, 0);
					that.$set(that.distForm.remain, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.to, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.can_count, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.to_exact, ''+id, 0);
					that.$set(that.secondFilterForm.filter_data_sum.exact_list, ''+id, []);
				});
				await that.getPointRules(that.secondFilterForm.point_type_ids);
				that.$set(that.secondFilterForm, 'origin_data', origin_data);
				that.$set(that.secondFilterForm, 'filter_data', JSON.parse(JSON.stringify(origin_data)));
				that.dialogFirstFilter = false;
				loading.close();
				that.dialogSecondFilter = true;
				that.calChoosedSum();
			},
			// 细筛合计行方法
			getSecondSummaries({
				columns,
				data
			}) {
				const that = this;
				const sums = [];
				const maxC = (columns || []).length;
				columns.forEach((column, index) => {
					if (index === 0) {
						sums[index] = '合计';
						return;
					} else if (index > 2 && index < (maxC - 1)) {
						if (!!that.secondFilterForm.filter_data_sum.to[column.property]) {
							sums[index] = ''+(that.secondFilterForm.filter_data_sum.to[column.property] || 0)+' / '+(that.secondFilterForm.filter_data_sum.can_count[column.property] || 0);
						} else {
							sums[index] = 0;
						}
						return;
					} else {
						sums[index] = '';
						return;
					}
				});
				return sums;
			},

			// 计算选中合计值
			calChoosedSum() {
				const that = this;
				let sum = {
					to: {},
					can_count: {},
					to_exact: {},
					exact_list: {},
				};
				(that.secondFilterForm.filter_data || []).forEach(d => {
					const pIds = Object.keys(d.points || {});
					pIds.forEach(pId => {
						sum.to[''+pId] = parseInt(sum.to[''+pId] || 0);
						sum.can_count[''+pId] = parseInt(sum.can_count[''+pId] || 0);
						sum.to_exact[''+pId] = parseInt(sum.to_exact[''+pId] || 0);
						sum.exact_list[''+pId] = sum.exact_list[''+pId] || [];
						
						sum.to[''+pId] += parseInt(d.to[''+pId] || 0);
						sum.can_count[''+pId] += parseInt(d.points[''+pId].can_count || 0);
						sum.to_exact[''+pId] += (d.to_exact[''+pId] || []).length;
						sum.exact_list[''+pId] =  [...sum.exact_list[''+pId], ...(d.to_exact[''+pId] || [])];
					});
				});
				that.$set(that.secondFilterForm, 'filter_data_sum', sum);
				
				(that.secondFilterForm.point_type_ids || []).forEach(pId => {
					that.distForm.remain[''+pId] = parseInt(that.distForm.all[''+pId] || 0) - parseInt(sum.to[''+pId] || 0);
				});
			},
			// 改变分配总数
			changeDistAll(val, pId){
				const that = this;
				// 自动分配
				that.autoDistByAllCount(val, pId);
			},
			// 改变一个分配
			changeDistOne(val, pId, row, rowIndex){
				const that = this;
				const exactCount = (row.to_exact[''+pId] || []).length;
				if(val > exactCount){
					// 增加选中点位
					const sub = val - exactCount;

					let result = [];
					const {
						list,
						count
					} = pointPlanUtil.getExactViewData(row.points[''+pId], pId, that.activeRuleMap.get(''+pId) || new Map());
					let toChoose = that.$refs.exactView.checkAutoForFather(list, true, sub, (row.to_exact[''+pId] || []));
					if((toChoose || []).length > 0){
						let temp = [];
						(toChoose || []).forEach(arr => {
							temp = [...temp, ...arr];
						});
						result.push({
							index: rowIndex,
							toChoose: temp
						});
					}
					result.forEach(res => {
						const list = [...(that.secondFilterForm.filter_data[parseInt(res.index)].to_exact[''+pId] || []), ...(res.toChoose||[])];
						that.$set(that.secondFilterForm.filter_data[parseInt(res.index)].to_exact, ''+pId, list);
						if(list.length > that.secondFilterForm.filter_data[parseInt(res.index)].to[''+pId]){
							that.$set(that.secondFilterForm.filter_data[parseInt(res.index)].to, ''+pId, list.length);
						}
					});
				}else{
					// todo 减少选中点位
					const sub = exactCount - val;
				}
				// 计算合计
				that.calChoosedSum();
			},
			// 根据总数量，自动分配
			autoDistByAllCount(val, pId){
				const that = this;
				if((val || 0) == 0){
					that.secondFilterForm.filter_data_sum.to_exact[''+pId] = 0;
					that.secondFilterForm.filter_data_sum.exact_list[''+pId] = [];
				}else{
					const exactCount = that.secondFilterForm.filter_data_sum.to_exact[''+pId] || 0;
					if(val > exactCount){
						// 增加选中点位
						const sub = val - exactCount;
						
						let countMap = new Map();
						if(that.distForm.dist_type == 1) countMap = that.aclAutoBuildingAverCount(pId, sub);
						let result = [];
						(that.secondFilterForm.filter_data || []).forEach((row, rowIndex) => {
							if(countMap.get(parseInt(row.id)).new_to > 0){
								const {
									list,
									count
								} = pointPlanUtil.getExactViewData(row.points[''+pId], pId, that.activeRuleMap.get(''+pId) || new Map());
								let toChoose = that.$refs.exactView.checkAutoForFather(list, true, countMap.get(parseInt(row.id)).new_to, (that.secondFilterForm.filter_data_sum.exact_list[''+pId] || []));
								if((toChoose || []).length > 0){
									let temp = [];
									(toChoose || []).forEach(arr => {
										temp = [...temp, ...arr];
									});
									result.push({
										index: rowIndex,
										toChoose: temp
									});
								}
							}
						});
						result.forEach(res => {
							const list = [...(that.secondFilterForm.filter_data[parseInt(res.index)].to_exact[''+pId] || []), ...(res.toChoose||[])];
							that.$set(that.secondFilterForm.filter_data[parseInt(res.index)].to_exact, ''+pId, list);
							if(list.length > that.secondFilterForm.filter_data[parseInt(res.index)].to[''+pId]){
								that.$set(that.secondFilterForm.filter_data[parseInt(res.index)].to, ''+pId, list.length);
							}
						});
					}else{
						// todo 减少选中点位
						const sub = exactCount - val;
					}
				}
				
				// 计算合计
				that.calChoosedSum();
			},
			// 平均分配，计算各楼盘应增加的分配
			aclAutoBuildingAverCount(pId, allCount){
				const that = this;
				let allCan = 0, allChoosed = 0, buildingCount = 0;
				
				const choosedList = (that.secondFilterForm.filter_data_sum.exact_list[''+pId] || []);
				let choosedMap = new Map();
				(choosedList || []).forEach(d => {
					let BC = choosedMap.get(parseInt(d.building_area_id)) || 0;
					BC++;
					choosedMap.set(parseInt(d.building_area_id), BC);
					allChoosed++;
				});
				
				
				const resultMap = new Map();
				(that.secondFilterForm.filter_data || []).forEach(d => {
					const can = (d.points[''+pId] || {}).can_count || 0;
					resultMap.set(parseInt(d.id), {
						can: can,
						to: choosedMap.get(parseInt(d.id)) || 0,
						new_to: 0,
					});
					allCan += can;
				});
				buildingCount = resultMap.size;
				if(buildingCount > 0){
					if(allCan <= (allCount+allChoosed)){
						resultMap.forEach((obj, id) => {
							obj.new_to = parseInt(obj.can) - parseInt(obj.to);
							obj.to = parseInt(obj.can);
						});
					}else{
						let remain = parseInt(allCount || 0);
						let index = 1;
						while(remain > 0){
							for(let obj of resultMap.values()){
								if(remain <= 0) break;
								if(obj.to < obj.can && obj.to < index){
									obj.new_to++;
									obj.to++;
									remain--;
								}
							}
							index++;
						}
					}
				}
				
				return resultMap;
			},
			// 精准选点结果
			choosedToExact(val) {
				const that = this;
				that.$set(that.secondFilterForm.filter_data[parseInt(that.exactRowIndex)].to_exact, that.exactPointTypeId, JSON.parse(JSON.stringify(val || [])));
				const toExactCount = that.secondFilterForm.filter_data[parseInt(that.exactRowIndex)].to_exact[that.exactPointTypeId].length;
				that.$set(that.secondFilterForm.filter_data[parseInt(that.exactRowIndex)].to, that.exactPointTypeId, parseInt(toExactCount));
				that.calChoosedSum();
			},
			// 精准选点
			onExact(row, index, pointId) {
				const that = this;
				const loading = common.showLoading('加载中');
				that.exactRowIndex = index;
				that.exactBuildingAreaId = '' + row.id;
				that.exactPointTypeId = '' + pointId;
				that.exactToExact = (row.to_exact || {})[''+pointId] || [];
				
				// 使用图形化选点页
				const {
					list,
					count
				} = pointPlanUtil.getExactViewData(row.points[''+pointId], pointId, that.activeRuleMap.get(''+pointId) || new Map());
				that.exactToExactViewData = list;
				that.exactTotal = count;
				that.exactCan = row.points[''+pointId].can_count || 0;
				
				loading.close();
				that.exactVisible = true;
			},
			// 删除分配列表行
			async delSecondRow(index){
				const that = this;
				const confirm = await common.confirmDialog('您确定要删除该楼盘？');
				if (!!confirm) {
					that.secondFilterForm.filter_data.splice(index, 1);
					that.calChoosedSum();
				}
			},
			
			// 校验总数分配完全
			validDistRemain(){
				const that = this;
				const pIds = Object.keys(that.distForm.remain);
				let flag = true;
				(pIds || []).forEach(pId => {
					if(that.distForm.remain[''+pId] != 0 && that.distForm.remain[''+pId] != Number.NaN) {
						flag = false;
					}
				});
				if(!flag){
					common.messageError('请将点位分配完全');
				}
				return flag;
			},
			// 生成setting数据
			genSettingData(){
				const that = this;
				let dateRange = JSON.parse(JSON.stringify(that.secondFilterForm.date_range));
				let pointTypes = (that.secondFilterForm.point_type_ids || []).filter(pId => {
					return (that.distForm.all[''+pId] || 0) > 0
				}).map(pId => {
					return {
						id: pId,
						name: that.point_types_map.get(parseInt(pId)).name
					}
				});
				let to = {};
				let buildings = [];
				(that.secondFilterForm.filter_data||[]).forEach(b => {
					let temp = 0;
					const tC = Object.keys(b.to);
					(tC || []).forEach(t => {
						temp += b.to[''+t] || 0;
					});
					if(temp > 0){
						buildings.push({
							id: b.id,
							name: b.name
						});
						const pIds = Object.keys(b.to_exact);
						(pIds || []).forEach(pId => {
							to[b.id+'_'+pId] = b.to_exact[''+pId] || [];
						});
					}
					
				})
				return {
					id: generateUUID(),
					dateRange,
					pointTypes,
					buildings,
					to,
					ruleMap: that.activeRuleMap || new Map(),
					out:{}
				}
			},
			// 确认分配
			confirmDist() {
				const that = this;
				const flag = that.validDistRemain();
				if(!flag) return false;
				that.$emit('confirm-setting', that.genSettingData());
				that.dialogSecondFilter = false;
			},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.search {
		.el-form {
			.el-input.long-input {
				width: 382px;
				margin: 0;
			}
		}
	}
	
	/deep/.map-dialog>.el-dialog--center>.el-dialog__body{
		padding: 0 !important;
	}
	
	.first-dialog{
		/deep/.el-dialog.el-dialog--center{
			margin-top: 5vh !important;
		}
	}

	/deep/.combo-tag {
		margin: 0 3px;
	}

	.search-form-card-group {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: flex-start;
		flex-wrap: wrap;

		.search-form-card {
			box-sizing: border-box;
			margin: 0 10px 20px 0;
			padding: 20px 5px;
			border: 1px solid #ddd;
			border-radius: 10px;
			box-shadow: 1px 1px 10px #eee;
			flex-grow: 0;
			width: 100%;
			position: relative;

			.card-title {
				position: absolute;
				background-color: #fff;
				padding: 5px 10px;
				height: 20px;
				line-height: 20px;
				left: 20px;
				top: -15px;
				font-weight: bold;
				font-size: 15px;
			}

			/deep/.el-form-item.el-form-item--mini {
				margin-bottom: 0;
			}
		}
	}

	.hiddenUploadInput {
		display: none;
	}

	/deep/.no-device-building {
		background-color: #ebebeb !important;
	}

	/deep/.can-num {
		background-color: #d7f0db !important;
	}
</style>
